package com.javasm.transfer.goodsTransfer;

import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.entity.goodsEntity.GdProduct;
import com.javasm.domin.entity.goodsEntity.GdType;
import com.javasm.domin.vo.goodsVo.GdProductVo;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.mapper.goodsMapper.GdTypeMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/11/22-15:15
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class GdProductTransfer extends BaseTransfer<GdProduct, GdProductVo> {

    private final GdTypeMapper gdTypeMapper;
    private final GdColourMapper gdColourMapper;
    private final GdBrandMapper gdBrandMapper;

    public List<GdProductVo> set(List<GdProduct> list){

        //装vo
        List<GdProductVo> gdProductVos = super.toVO(list);

        //遍历vo
        for (int i = 0; i < gdProductVos.size(); i++) {
            //拿到实体类对象
            GdProduct gdProduct = list.get(i);
            //拿到product对象中的id
            //品牌id，颜色id，类型id
            Integer brandId = gdProduct.getBrandId();
            GdBrand gdBrand = gdBrandMapper.selectById(brandId);
            Integer colourId = gdProduct.getColourId();
            GdColour gdColour = gdColourMapper.selectById(colourId);
            Integer typeId = gdProduct.getTypeId();
            GdType gdType = gdTypeMapper.selectById(typeId);
            GdProductVo gdProductVo = gdProductVos.get(i);
            //判断是否为空进行赋值
            gdProductVo.setBrandName(gdBrand==null?"":gdBrand.getBrandName());
            gdProductVo.setColourName(gdColour==null?"":gdColour.getColourName());
            gdProductVo.setTypeName(gdType==null?"":gdType.getTypeName());


        }

        return gdProductVos;
    }



}
